package development;

import state.GameConstants;
import state.GameForm;
import state.GameGlobal;
import state.GameImage;
import state.Key;
import state.Sprite;
import state.TouchScreenListener;
import state.util.Hashtable;
import state.util.ImageUtil;
import stateframework_particle.view.StateFramework_ParticleResources;

public class FrmTestTouchScreen extends GameForm {
  private GameImage buttonImage = null;
  private GameImage lightButtonImage = null;

  private Sprite buttonSprite = null;

  private static GameForm singleton = null;

  public static GameForm instance() {
    if (singleton == null) {
      singleton = new FrmTestTouchScreen();
    }
    return singleton;
  }

  public void init(Hashtable parameters) {
    buttonImage = new GameImage(StateFramework_ParticleResources.image_button_nho, null, null).setStatic(true);
    lightButtonImage = ImageUtil.makeBrighter(buttonImage, 4);

    buttonSprite = new Sprite(buttonImage, _manager, 50, 50, GameConstants.TOP_LEFT_ANCHOR);
    TouchScreenListener1 touchScreenListener1 = new TouchScreenListener1();
    buttonSprite.setTouchScreenListener(touchScreenListener1);
  }
  
  class TouchScreenListener1 implements TouchScreenListener {

    public void pointerDragged(Sprite source, int x1, int y1) {
      source.setPosition(x1 - source.getWidth() / 2, y1 - source.getHeight() / 2);
    }

    public void pointerPressed(Sprite source, int x1, int y1) {
    }

    public void pointerReleased(Sprite source, int x1, int y1) {
      if (source.getImage() == buttonImage) {
        source.setImage(lightButtonImage);
      } else {
        source.setImage(buttonImage);
      }
    }
  }

  public void keyReleased(int keyCode) {
    if (keyCode == Key.SOFT_RIGHT) {
      GameGlobal.nextState(FrmMenu.instance(), null);
    }
  }

  public void destroy() {
    buttonImage = null;
    lightButtonImage = null;

    buttonSprite = null;
  }
}
